package com.github.rxyor.example.transaction.goods.service.impl;

import com.github.rxyor.example.transaction.goods.mapper.GoodsMapper;
import com.github.rxyor.example.transaction.goods.service.GoodsService;
import java.math.BigDecimal;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 *<p>
 *
 *</p>
 *
 * @author liuyang
 * @date 2019/9/4 周三 17:49:00
 * @since 1.0.0
 */
@AllArgsConstructor
@Service("goodsService")
public class GoodsServiceImpl implements GoodsService {

    private final GoodsMapper goodsMapper;

    @Transactional
    @Override
    public void risePriceById(Long id, BigDecimal floatedPrice) {
        int affectRows = goodsMapper.risePriceById(id, floatedPrice);
        if (affectRows != 1) {
            throw new RuntimeException("调整价格失败, 数据变更条数不在预期之内");
        }
    }

    @Override
    public void subtractStockById(Long id) {
        int affectRows = goodsMapper.subtractStockById(id);
        if (affectRows != 1) {
            throw new RuntimeException("减库存失败, 数据变更条数不在预期之内");
        }
    }
}
